

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="python" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="python" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>QUANTAXIS.QAFetch.QAQuery_Advance &mdash; QUANTAXIS 1.0.39 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> QUANTAXIS
          

          
          </a>

          
            
            
              <div class="version">
                1.0.39
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">QUANTAXIS</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
          <li><a href="../QAFetch.html">QUANTAXIS.QAFetch</a> &raquo;</li>
        
      <li>QUANTAXIS.QAFetch.QAQuery_Advance</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for QUANTAXIS.QAFetch.QAQuery_Advance</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1">#</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016-2018 yutiansut/QUANTAXIS</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in all</span>
<span class="c1"># copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c1"># SOFTWARE.</span>

<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">pymongo</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pandas</span> <span class="k">import</span> <span class="n">DataFrame</span>

<span class="kn">from</span> <span class="nn">QUANTAXIS.QAData</span> <span class="k">import</span> <span class="p">(</span><span class="n">QA_DataStruct_Index_day</span><span class="p">,</span> <span class="n">QA_DataStruct_Index_min</span><span class="p">,</span>
                              <span class="n">QA_DataStruct_Stock_block</span><span class="p">,</span>
                              <span class="n">QA_DataStruct_Stock_day</span><span class="p">,</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">,</span>
                              <span class="n">QA_DataStruct_Stock_transaction</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAFetch.QAQuery</span> <span class="k">import</span> <span class="p">(</span><span class="n">QA_fetch_index_day</span><span class="p">,</span>
                                       <span class="n">QA_fetch_index_min</span><span class="p">,</span>
                                       <span class="n">QA_fetch_stock_day</span><span class="p">,</span>
                                       <span class="n">QA_fetch_stock_full</span><span class="p">,</span>
                                       <span class="n">QA_fetch_stock_min</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAUtil</span> <span class="k">import</span> <span class="p">(</span><span class="n">DATABASE</span><span class="p">,</span> <span class="n">QA_Setting</span><span class="p">,</span> <span class="n">QA_util_date_stamp</span><span class="p">,</span>
                              <span class="n">QA_util_date_valid</span><span class="p">,</span> <span class="n">QA_util_log_info</span><span class="p">,</span>
                              <span class="n">QA_util_time_stamp</span><span class="p">)</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">按要求从数据库取数据，并转换成numpy结构</span>

<span class="sd">总体思路：</span>
<span class="sd">⚙️QA_fetch_***_adv</span>
<span class="sd">📍⚙️QA_fetch_*** 🐌 获取数据collections从mongodb中 🐌 返回DataFrame , </span>
<span class="sd">📍📍⚙️用返回的 DataFrame 初始化 ️QA_DataStruct_***</span>

<span class="sd">类型***有</span>
<span class="sd">_Stock_day</span>
<span class="sd">_Stock_min</span>
<span class="sd">_Index_day</span>
<span class="sd">_Index_min</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="c1"># start=&#39;1990-01-01&#39;,end=str(datetime.date.today())</span>


<div class="viewcode-block" id="QA_fetch_stock_day_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_day_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_day_adv</span><span class="p">(</span>
        <span class="n">code</span><span class="p">,</span>
        <span class="n">start</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">if_drop_index</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="c1"># 🛠 todo collections 参数没有用到， 且数据库是固定的， 这个变量后期去掉</span>
        <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_day</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>

<span class="sd">    :param code:  股票代码</span>
<span class="sd">    :param start: 开始日期</span>
<span class="sd">    :param end:   结束日期</span>
<span class="sd">    :param if_drop_index:</span>
<span class="sd">    :param collections: 默认数据库</span>
<span class="sd">    :return: 如果股票代码不存 或者开始结束日期不存在 在返回 None ，合法返回 QA_DataStruct_Stock_day 数据</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="s1">&#39;获取股票日线&#39;</span>
    <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">end</span>
    <span class="n">start</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">start</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
    <span class="n">end</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">end</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>

    <span class="k">if</span> <span class="n">start</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
        <span class="n">start</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
        <span class="n">end</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">())</span>

    <span class="n">res</span> <span class="o">=</span> <span class="n">QA_fetch_stock_day</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;pd&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># 🛠 todo 报告是代码不合法，还是日期不合法</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_day_adv parameter code=</span><span class="si">%s</span><span class="s2"> , start=</span><span class="si">%s</span><span class="s2">, end=</span><span class="si">%s</span><span class="s2"> call QA_fetch_stock_day return None&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">None</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res_reset_index</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="n">if_drop_index</span><span class="p">)</span>
        <span class="c1"># if res_reset_index is None:</span>
        <span class="c1">#     print(&quot;💢 Error QA_fetch_stock_day_adv set index &#39;datetime, code&#39; return None&quot;)</span>
        <span class="c1">#     return None</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_day</span><span class="p">(</span><span class="n">res_reset_index</span><span class="p">);</span></div>


<div class="viewcode-block" id="QA_fetch_stock_min_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_min_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_min_adv</span><span class="p">(</span>
        <span class="n">code</span><span class="p">,</span>
        <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span>
        <span class="n">if_drop_index</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="c1"># 🛠 todo collections 参数没有用到， 且数据库是固定的， 这个变量后期去掉</span>
        <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_min</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    &#39;获取股票分钟线&#39;</span>
<span class="sd">    :param code:  字符串str eg 600085</span>
<span class="sd">    :param start: 字符串str 开始日期 eg 2011-01-01</span>
<span class="sd">    :param end:   字符串str 结束日期 eg 2011-05-01</span>
<span class="sd">    :param frequence: 字符串str 分钟线的类型 支持 1min 1m 5min 5m 15min 15m 30min 30m 60min 60m 类型</span>
<span class="sd">    :param if_drop_index: Ture False ， dataframe drop index or not</span>
<span class="sd">    :param collections: mongodb 数据库</span>
<span class="sd">    :return: QA_DataStruct_Stock_min 类型</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">if</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;1m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;1min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;5m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;5min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;15m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;15min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;30m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;30min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;60min&#39;</span><span class="p">,</span> <span class="s1">&#39;60m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;60min&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_min_adv parameter frequence=</span><span class="si">%s</span><span class="s2"> is none of 1min 1m 5min 5m 15min 15m 30min 30m 60min 60m&quot;</span><span class="o">%</span><span class="n">frequence</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">None</span>

    <span class="c1">#__data = [] 未使用</span>

    <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">end</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">start</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span><span class="p">:</span>
        <span class="n">start</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> 09:30:00&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">start</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">end</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span><span class="p">:</span>
        <span class="n">end</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> 15:00:00&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">end</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">start</span> <span class="o">==</span> <span class="n">end</span><span class="p">:</span>
        <span class="c1"># 🛠 todo 如果相等，根据 frequence 获取开始时间的 时间段 QA_fetch_stock_min， 不支持start end是相等的</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_min_adv parameter code=</span><span class="si">%s</span><span class="s2"> , start=</span><span class="si">%s</span><span class="s2">, end=</span><span class="si">%s</span><span class="s2"> is equal, should have time span! &quot;</span><span class="o">%</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">None</span>

    <span class="c1"># 🛠 todo 报告错误 如果开始时间 在 结束时间之后</span>

    <span class="n">res</span> <span class="o">=</span> <span class="n">QA_fetch_stock_min</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;pd&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="n">frequence</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_min_adv parameter code=</span><span class="si">%s</span><span class="s2"> , start=</span><span class="si">%s</span><span class="s2">, end=</span><span class="si">%s</span><span class="s2"> frequence=</span><span class="si">%s</span><span class="s2"> call QA_fetch_stock_min return None&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">,</span><span class="n">frequence</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">None</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res_set_index</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span><span class="n">drop</span><span class="o">=</span><span class="n">if_drop_index</span><span class="p">)</span>
        <span class="c1"># if res_set_index is None:</span>
        <span class="c1">#     print(&quot;💢 Error QA_fetch_stock_min_adv set index &#39;datetime, code&#39; return None&quot;)</span>
        <span class="c1">#     return None</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_min</span><span class="p">(</span><span class="n">res_set_index</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_fetch_stock_day_full_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_day_full_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_day_full_adv</span><span class="p">(</span><span class="n">date</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    &#39;返回全市场某一天的数据&#39;</span>
<span class="sd">    :param date:</span>
<span class="sd">    :return: QA_DataStruct_Stock_day类 型数据</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="c1"># 🛠 todo 检查日期data参数</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">QA_fetch_stock_full</span><span class="p">(</span><span class="n">date</span><span class="p">,</span> <span class="s1">&#39;pd&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_day_full_adv parameter date=</span><span class="si">%s</span><span class="s2"> call QA_fetch_stock_full return None&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">date</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">None</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res_set_index</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="c1"># if res_set_index is None:</span>
        <span class="c1">#     print(&quot;💢 Error QA_fetch_stock_day_full set index &#39;date, code&#39; return None&quot;)</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_day</span><span class="p">(</span><span class="n">res_set_index</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_fetch_index_day_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_index_day_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_index_day_adv</span><span class="p">(</span>
        <span class="n">code</span><span class="p">,</span>
        <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">if_drop_index</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="c1"># 🛠 todo collections 参数没有用到， 且数据库是固定的， 这个变量后期去掉</span>
        <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">index_day</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    :param code: code:  字符串str eg 600085</span>
<span class="sd">    :param start:  字符串str 开始日期 eg 2011-01-01</span>
<span class="sd">    :param end:  字符串str 结束日期 eg 2011-05-01</span>
<span class="sd">    :param if_drop_index: Ture False ， dataframe drop index or not</span>
<span class="sd">    :param collections:  mongodb 数据库</span>
<span class="sd">    :return:</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="s1">&#39;获取指数日线&#39;</span>
    <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">end</span>
    <span class="n">start</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">start</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
    <span class="n">end</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">end</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>

    <span class="c1"># 🛠 todo 报告错误 如果开始时间 在 结束时间之后</span>
    <span class="c1"># 🛠 todo 如果相等</span>

    <span class="n">res</span> <span class="o">=</span> <span class="n">QA_fetch_index_day</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;pd&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_index_day_adv parameter code=</span><span class="si">%s</span><span class="s2"> start=</span><span class="si">%s</span><span class="s2"> end=</span><span class="si">%s</span><span class="s2"> call QA_fetch_index_day return None&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res_set_index</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="n">if_drop_index</span><span class="p">)</span>
        <span class="c1"># if res_set_index is None:</span>
        <span class="c1">#     print(&quot;💢 Error QA_fetch_index_day_adv set index &#39;date, code&#39; return None&quot;)</span>
        <span class="c1">#     return None</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Index_day</span><span class="p">(</span><span class="n">res_set_index</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_fetch_index_min_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_index_min_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_index_min_adv</span><span class="p">(</span>
        <span class="n">code</span><span class="p">,</span>
        <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span>
        <span class="n">if_drop_index</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">index_min</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    &#39;获取股票分钟线&#39;</span>
<span class="sd">    :param code:</span>
<span class="sd">    :param start:</span>
<span class="sd">    :param end:</span>
<span class="sd">    :param frequence:</span>
<span class="sd">    :param if_drop_index:</span>
<span class="sd">    :param collections:</span>
<span class="sd">    :return:</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">if</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;1m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;1min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;5m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;5min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;15m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;15min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;30m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;30min&#39;</span>
    <span class="k">elif</span> <span class="n">frequence</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;60min&#39;</span><span class="p">,</span> <span class="s1">&#39;60m&#39;</span><span class="p">]:</span>
        <span class="n">frequence</span> <span class="o">=</span> <span class="s1">&#39;60min&#39;</span>

    <span class="c1">#__data = [] 没有使用</span>

    <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">end</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">start</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span><span class="p">:</span>
        <span class="n">start</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> 09:30:00&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">start</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">end</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span><span class="p">:</span>
        <span class="n">end</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> 15:00:00&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">end</span><span class="p">)</span>

    <span class="c1"># 🛠 todo 报告错误 如果开始时间 在 结束时间之后</span>

    <span class="c1">#if start == end:</span>
    <span class="c1"># 🛠 todo 如果相等，根据 frequence 获取开始时间的 时间段 QA_fetch_index_min_adv， 不支持start end是相等的</span>
    <span class="c1">#print(&quot;💢 Error QA_fetch_index_min_adv parameter code=%s , start=%s, end=%s is equal, should have time span! &quot; % (code, start, end))</span>
    <span class="c1">#return None</span>

    <span class="n">res</span> <span class="o">=</span>  <span class="n">QA_fetch_index_min</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">,</span><span class="nb">format</span><span class="o">=</span><span class="s1">&#39;pd&#39;</span><span class="p">,</span><span class="n">frequence</span><span class="o">=</span><span class="n">frequence</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">res</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_index_min_adv parameter code=</span><span class="si">%s</span><span class="s2"> start=</span><span class="si">%s</span><span class="s2"> end=</span><span class="si">%s</span><span class="s2"> frequence=</span><span class="si">%s</span><span class="s2"> call QA_fetch_index_min return None&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">,</span><span class="n">frequence</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res_reset_index</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="n">if_drop_index</span><span class="p">)</span>
        <span class="c1"># if res_reset_index is None:</span>
        <span class="c1">#     print(&quot;💢 Error QA_fetch_index_min_adv set index &#39;date, code&#39; return None&quot;)</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Index_min</span><span class="p">(</span><span class="n">res_reset_index</span><span class="p">)</span></div>

<div class="viewcode-block" id="QA_fetch_stock_transaction_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_transaction_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_transaction_adv</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">if_drop_index</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span><span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_transaction</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>

<span class="sd">    :param code:</span>
<span class="sd">    :param start:</span>
<span class="sd">    :param end:</span>
<span class="sd">    :param if_drop_index:</span>
<span class="sd">    :param collections:</span>
<span class="sd">    :return:</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="k">if</span> <span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">end</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">([</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">({</span>
        <span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="s2">&quot;date&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="s2">&quot;$gte&quot;</span><span class="p">:</span> <span class="n">start</span><span class="p">,</span>
            <span class="s2">&quot;$lte&quot;</span><span class="p">:</span> <span class="n">end</span>
        <span class="p">}})])</span>

    <span class="n">data</span><span class="p">[</span><span class="s1">&#39;datetime&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;datetime&#39;</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">QA_DataStruct_Stock_transaction</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="n">drop</span><span class="o">=</span><span class="n">if_drop_index</span><span class="p">))</span></div>

<span class="c1"># 没有被使用， 和下面的QA_fetch_stock_list_adv函数是一致的</span>
<span class="c1"># def QA_fetch_security_list_adv(collections=DATABASE.stock_list):</span>
<span class="c1">#     &#39;获取股票列表&#39;</span>
<span class="c1">#     return pd.DataFrame([item for item in collections.find()]).drop(&#39;_id&#39;, axis=1, inplace=False)</span>


<div class="viewcode-block" id="QA_fetch_stock_list_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_list_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_list_adv</span><span class="p">(</span><span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_list</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    &#39;获取股票列表&#39;</span>
<span class="sd">    :param collections: mongodb 数据库</span>
<span class="sd">    :return: DataFrame</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="n">stock_list_items</span> <span class="o">=</span> <span class="p">[</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">()];</span>
    <span class="k">if</span> <span class="n">stock_list_items</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_list_adv return None, maybe the DATABASE.stock_list have no DATA!&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">None</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list_items</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_list_adv call item for item in collections.find() return 0 item, maybe the DATABASE.stock_list is empty!&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">stock_list_items</span><span class="p">)</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s1">&#39;_id&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_fetch_stock_block_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_block_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_block_adv</span><span class="p">(</span><span class="n">code</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">blockname</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">stock_block</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    返回板块 ❌</span>
<span class="sd">    :param code:</span>
<span class="sd">    :param blockname:</span>
<span class="sd">    :param collections: 默认数据库 stock_block</span>
<span class="sd">    :return: QA_DataStruct_Stock_block</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">if</span> <span class="n">code</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">blockname</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># 返回这个股票代码所属的板块</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">([</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="n">code</span><span class="p">})])</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s1">&#39;_id&#39;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_block</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">())</span>
    <span class="k">elif</span> <span class="n">blockname</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">code</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># 返回该板块所属的股票</span>
        <span class="n">items_from_collections</span> <span class="o">=</span> <span class="p">[</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;blockname&#39;</span><span class="p">:</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">blockname</span><span class="p">)})]</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">items_from_collections</span><span class="p">)</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s1">&#39;_id&#39;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="c1"># 🛠 todo 返回 这个板块所有的股票</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error blockname is Not none code none, return all code from its block name have not implemented yet !&quot;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># 🛠 todo 返回 判断 这个股票是否和属于该板块</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">([</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">()])</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s1">&#39;_id&#39;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">data_set_index</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">drop_duplicates</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">QA_DataStruct_Stock_block</span><span class="p">(</span><span class="n">data_set_index</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_fetch_stock_realtime_adv"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAFetch.html#QUANTAXIS.QAFetch.QAQuery_Advance.QA_fetch_stock_realtime_adv">[docs]</a><span class="k">def</span> <span class="nf">QA_fetch_stock_realtime_adv</span><span class="p">(</span><span class="n">code</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                <span class="n">num</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                <span class="n">collections</span><span class="o">=</span><span class="n">DATABASE</span><span class="o">.</span><span class="n">get_collection</span><span class="p">(</span><span class="s1">&#39;realtime_</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()))):</span>
    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    返回当日的上下五档, code可以是股票可以是list, num是每个股票获取的数量</span>
<span class="sd">    :param code:</span>
<span class="sd">    :param num:</span>
<span class="sd">    :param collections:  realtime_XXXX-XX-XX 每天实时时间</span>
<span class="sd">    :return: DataFrame</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">if</span> <span class="n">code</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1">#code 必须转换成list 去查询数据库</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">code</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_realtime_adv parameter code is not List type or String type&quot;</span><span class="p">)</span>

        <span class="n">items_from_collections</span> <span class="o">=</span> <span class="p">[</span><span class="n">item</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">collections</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;$in&#39;</span><span class="p">:</span> <span class="n">code</span><span class="p">}},</span> <span class="n">limit</span><span class="o">=</span><span class="n">num</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">sort</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">DESCENDING</span><span class="p">)])]</span>
        <span class="k">if</span> <span class="n">items_from_collections</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_realtime_adv find parameter code=</span><span class="si">{}</span><span class="s2"> num=</span><span class="si">{}</span><span class="s2"> collection=</span><span class="si">{}</span><span class="s2"> return NOne&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="n">num</span><span class="p">,</span><span class="n">collections</span><span class="p">))</span>
            <span class="k">return</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">items_from_collections</span><span class="p">)</span>
        <span class="n">data_set_index</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;datetime&#39;</span><span class="p">,</span> <span class="s1">&#39;code&#39;</span><span class="p">],</span> <span class="n">drop</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s1">&#39;_id&#39;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data_set_index</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;💢 Error QA_fetch_stock_realtime_adv parameter code is None&quot;</span><span class="p">)</span></div>


<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">QA_fetch_stock_realtime_adv</span><span class="p">([</span><span class="s1">&#39;000001&#39;</span><span class="p">,</span> <span class="s1">&#39;000002&#39;</span><span class="p">],</span> <span class="n">num</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, yutiansut.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'1.0.39',
            LANGUAGE:'python',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>